﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Acms.SqlDal;
using System.Collections;

namespace Acms.Bll
{
    public class FileInfo : BaseItem
    {
        private FileInfo() : base() { }
        private FileInfo(Hashtable table) : base(table) { }
        private FileInfo(Hashtable table, List<FileInfo> collection) : base(table, collection) { }

        protected override Base CreateDal()
        {
            return new FileInfoDal();
        }

        private static FileInfo Get(Hashtable table)
        {
            if (table != null)
            {
                return new FileInfo(table);
            }
            else
            {
                return null;
            }
        }

        private static List<FileInfo> Get(Hashtable[] tables)
        {
            if (tables != null)
            {
                List<FileInfo> tmp = new List<FileInfo>();
                foreach (Hashtable table in tables)
                {
                    tmp.Add(new FileInfo(table, tmp));
                }
                return tmp;
            }
            else
            {
                return null;
            }
        }

        protected override void Load(Hashtable table)
        {
            id = (int)table[FileInfoDal.Fields.Id];
            name = (string)table[FileInfoDal.Fields.Name];
            size = (long)table[FileInfoDal.Fields.Size];
            fileType = (int)table[FileInfoDal.Fields.FileType];
            contentType = (string)table[FileInfoDal.Fields.ContentType];
            extension = (string)table[FileInfoDal.Fields.Extension];
            width = (int?)table[FileInfoDal.Fields.Width];
            height = (int?)table[FileInfoDal.Fields.Height];
            LogDownload = (bool)table[FileInfoDal.Fields.LogDownload];
        }

        public static FileInfo GetById(int id)
        {
            FileInfoDal dal = new FileInfoDal();
            return Get(dal.GetById(id));
        }

        private int id;
        public int Id
        {
            get { return id; }
        }

        private string name;
        public string Name
        {
            get { return name; }
            set { name = value; }
        }

        private long size;
        public long Size
        {
            get { return size; }
            set { size = value; }
        }

        private int fileType;
        public Acms.Bll.File.FileTypes FileType
        {
            get { return (Acms.Bll.File.FileTypes)fileType; }
            set { fileType = (int)value; }
        }

        private string contentType;
        public string ContentType
        {
            get { return contentType; }
            set { contentType = value; }
        }

        private string extension;
        public string Extension
        {
            get { return extension; }
        }

        private int? width;
        public int? Width
        {
            get { return width; }
            set { width = value; }
        }


        private int? height;
        public int? Height
        {
            get { return height; }
            set { height = value; }
        }

        public bool LogDownload { get; set; }

        public new void Delete()
        {
            base.Delete();
        }

        protected override void DeleteRecord(object concurencyId, Base dal)
        {
            ((FileInfoDal)dal).Delete(id, concurencyId);
        }
    }
}
